<template>
	<view>
		<view class="book_info" v-for="(item, index) in shelfDatas" :key="index">
			<view class="book" @click="gotoBookContent(item)">
				<view class="book_img">
					<image style="width: 80px;height: 100px;" :src="item.bookImgUrl" />
				</view>
				<view class="book_text_list">
					<view class="book_name">
						<text>{{ item.bookName }}</text>
					</view>
					<view class="book_author">
						<text>{{ item.author }}</text>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						<text>{{ item.bookStatus }}</text>
					</view>
					<view>
						<text>您读到：{{ item.userReadChapterName }}</text>
					</view>
				</view>
			</view>
			<view class="close" @click="deleteShelf(item.id)">
				<text>X</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data () {
			return {
				shelfDatas: [],
				pageIndex: 1,
				pageSize: 20
			}
		},
		onShow() {
			this.getShelfDatas();
		},
		methods: {
			// 获取书架列表
			getShelfDatas() {
				uni.showLoading({
					title: '查询中,请耐心等待一下!',
					mask: true
				});
				this.$api.get({
					url: '/app/bqg/shelf/list',
					params: {
						pageIndex: this.pageIndex,
						pageSize: this.pageSize
					}
				}).then(res => {
					// console.log('res', res);
					if (res && res.data.code === 0) {
						this.shelfDatas = res.data.shelfList
					}
					uni.hideLoading();
				}).catch(error => {
					console.log('error', error);
					uni.hideLoading();
				})
			},
			gotoBookContent(item) {
				console.log('item', item);
				uni.navigateTo({
					url: '/pages/book/read?chapterUrl=' + item.chapterUrl + '&bookWebId=' + item.bookWebId
				});
			},
			deleteShelf(id) {
				const _that = this;
				uni.showModal({
					title: '提示',
					content: '确定删除吗？',
					success(res) {
						if (res.confirm) {
							_that.sureDelete(id);
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				})
			},
			sureDelete(id) {
				uni.showLoading({
					title: '删除中,请耐心等待一下!',
					mask: true
				});
				this.$api.post({
					url: '/app/bqg/shelf/deleteShelf',
					params: {
						id: id
					}
				}).then(res => {
					if (res && res.data.code === 0) {
						
					}
					uni.hideLoading();
				}).catch(error => {
					uni.hideLoading();
				})
			}
		}
	}
</script>

<style lang="scss">
	.book_info {
		display: flex;
		// align-items: center;
		margin-bottom: 10rpx;
		background: #fef9ef;
		margin: 10rpx 10rpx 0 10rpx;
		border-radius: 20rpx;
		
		.book {
			display: flex;
		}
		
		.book_img {
			margin-left: 10rpx;
			margin-top: 10rpx;
		}
		
		.book_text_list {
			margin-left: 10rpx;
			margin-right: 10rpx;
			font-size: 0.8rem;
			
			.book_name {}
			.book_author {}
			.book_profile {}
		}
		
		.close {
			margin-left: auto;
			margin-top: 10rpx;
			margin-right: 10rpx;
		}
	}
</style>